#include "qeditorlabel.h"

#include "qabstractproperty.h"


#include <QHBoxLayout>

using namespace SHAREDLIB;

QEditorLabel::QEditorLabel(SHAREDLIB::QAbstractProperty *property) :
    QWidget(NULL),
    m_icon(new QLabel(this)),
    m_text(new QLabel(this)),
    m_property(property)
{
    this->setFocusPolicy(Qt::StrongFocus);
    m_text->setText(m_property->valueText());
    QIcon icon=m_property->valueIcon();
    if(icon.isNull())
    {
        m_icon->setVisible(false);
    }
    else
    {
        QPixmap pix=icon.pixmap(QSize(16,16));
        m_icon->setFixedSize(16,16);
        m_icon->setPixmap(pix);
    }

    QHBoxLayout *l=new QHBoxLayout;
    this->setLayout(l);
    l->setContentsMargins(2,0,2,0);
    l->setSpacing(0);
    l->addWidget(m_icon);
    l->addWidget(m_text);

    connect(m_property,SIGNAL(showValueChanged()),this,SLOT(propertyValueChanged()));
}

void QEditorLabel::propertyValueChanged()
{
    m_text->setText(m_property->valueText());
    QIcon icon=m_property->valueIcon();
    if(icon.isNull())
    {
        m_icon->setVisible(false);
    }
    else
    {
        QPixmap pix=icon.pixmap(QSize(16,16));
        m_icon->setFixedSize(16,16);
        m_icon->setPixmap(pix);
    }
}
